package com.lemei.cn.activity;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.lemei.cn.adpter.MyFragmentAdpter;
import com.lemei.cn.fragment.BuHuo;
import com.lemei.cn.fragment.BuHuoChaXun;
import com.lemei.cn.fragment.LeiJi;
import com.lemei.cn.fragment.LeiJiChaXun;
import com.lemei.cn.fragment.PanDian;
import com.lemei.cn.fragment.PanDianChaXun;
import com.lemei.cn.lemeiapp.BasicActivity;
import com.lemei.cn.lemeiapp.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 赵航 on 2017/5/26.
 */

public class MianActivity extends BasicActivity {

    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    private List<Fragment> mFragments = new ArrayList<>();
    private String[] arr = {"补货","补货查询","累计","累计查询","盘点","盘点查询"};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        BuHuo buHuo = new BuHuo();
        BuHuoChaXun buHuoChaXun = new BuHuoChaXun();
        LeiJi leiJi = new LeiJi();
        LeiJiChaXun leiJiChaXun = new LeiJiChaXun();
        PanDian panDian = new PanDian();
        PanDianChaXun panDianChaXun = new PanDianChaXun();

        mFragments.add(buHuo);
        mFragments.add(buHuoChaXun);
        mFragments.add(leiJi);
        mFragments.add(leiJiChaXun);
        mFragments.add(panDian);
        mFragments.add(panDianChaXun);



        initView();
        initData();
    }

    private void initData() {


        initViweAdpter();
    }

    private void initViweAdpter() {

        MyFragmentAdpter adpter = new MyFragmentAdpter(getSupportFragmentManager(),mFragments,arr );

        mViewPager.setAdapter(adpter);

        mTabLayout.setupWithViewPager(mViewPager);
    }

    private void initView() {

        mTabLayout = (TabLayout) findViewById(R.id.mian_tebLayout);
        mViewPager = (ViewPager) findViewById(R.id.mian_viewpager);

    }

    @Override
    public void onBackPressed() {
        //  super.onBackPressed();
        MaterialDialog.Builder builder = new MaterialDialog.Builder(MianActivity.this);
        builder.title("退出提示");
        builder.content("亲，确定没点错");
        builder.negativeText("点错了");
        builder.positiveText("确定");
        builder.show();
        builder.onNegative(new MaterialDialog.SingleButtonCallback() {
            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                dialog.dismiss();
            }
        });
        builder.onPositive(new MaterialDialog.SingleButtonCallback() {
            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {

                dialog.dismiss();
                finish();
            }
        });


    }
}
